//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System.Windows;
using System.Windows.Controls;
using Microsoft.Research.ScientificWorkflow.ManagementStudioControls.WorkflowManagerModule;

namespace Microsoft.Research.ScientificWorkflow.ManagementStudioControls
{
    /// <summary>
    /// Interaction logic for WorkflowManagerView.xaml. It contains the logic to be executed when the treeview item is selected.
    /// </summary>
    public sealed partial class WorkflowManagerView : UserControl
    {
        /// <summary>
        /// Constructor.
        /// </summary>
        public WorkflowManagerView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// The presenter for this view.
        /// </summary>
        public object Presenter
        {
            get
            {
               return this.DataContext;
            }
            set
            {
                this.DataContext = value;
            }
        }

        /// <summary>
        /// The selected item changed event on the treeview. This executes the filter.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The event arguments.</param>
        private void filterHost_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            WorkflowManagerLeftPanePresenter leftPanePresenter = this.DataContext as WorkflowManagerLeftPanePresenter;
            leftPanePresenter.FilterSelected.Execute(e.NewValue as WorkflowManagerFilterModel);
        }

        /// <summary>
        /// Add the content to the search pane.
        /// </summary>
        /// <param name="searchControl">The search pane.</param>
        public void AddToSearchPane(UIElement searchControl)
        {
            this.SearchControlHolder.Children.Clear();
            this.SearchControlHolder.Children.Add(searchControl);
        }
    }
}
